// pages/saleUpload/saleUpload.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indoor:[],
    outdoor:[],
    house_type:[],
    house_img:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  //室内图
  indoor(e){
    let imgUrl = e.detail.current;
    let indoor = this.data.indoor;
    this.upload(imgUrl,indoor)
  },
  //户型图
  houseType(e){
    let imgUrl = e.detail.current;
    let house_type = this.data.house_type;
    this.upload(imgUrl,house_type)
  },
  //室外图
  outdoor(e){
    let imgUrl = e.detail.current;
    let outdoor = this.data.outdoor;
    this.upload(imgUrl,outdoor)
  },
  //封面图
  house_img(e){
    let imgUrl = e.detail.current;
    let house_img = this.data.house_img;
    this.upload(imgUrl,house_img)
  },
  //上传
  upload(img,newImg){
    let that = this;
    img.map(function(v,k){
      wx.uploadFile({
        url:'http://www.tenement.com/api/skx/upload',
        filePath: v,
        name: 'file',
        formData: {
          'user': 'test'
        },
        success:ret=>{
          let data = JSON.parse(ret.data);
            newImg.push(data.data);
            that.setData({
              newImg
            })
        }
      })
    })
  },
  complete(){
    let pages = getCurrentPages();//当前页的数据
    let prevPage = pages[pages.length-2];
    prevPage.setData({
      house_type:this.data.house_type,
      house_img:this.data.house_img,
      indoor:this.data.indoor,
      outdoor:this.data.outdoor//是否修改上一页的属性值
    })
    wx.navigateBack()
  }
})